/**
 * 部门管理初始化
 */
var Consultant = {
    id: "ConsultantTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Consultant.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: 'reservationsId', field: 'reservationsId', visible: false, align: 'center', valign: 'middle'},
        {title: '病历号', field: 'medicalRecordNumber', align: 'center', valign: 'middle', sortable: true, width: 100},
        {
            title: '客户姓名', field: 'customerName', align: 'center', valign: 'middle', sortable: true, width: 100,
            formatter: function (value, row, index) {
                return "<a href='javascript:;' onclick='Consultant.consultantToDetail(" + '"' + row.id + '"' + ")'>" + row.customerName + "</a>"
            },
        },
        {title: '电话', field: 'customerPhone', align: 'center', valign: 'middle', sortable: true, width: 110},
        {
            title: '性别', field: 'customerSex', align: 'center', valign: 'middle', sortable: true, width: 60,
            formatter: function (value, row, index) {
                if (value == 1) {
                    return "男";
                } else if (value == 2) {
                    return "女"
                } else {
                    return "未知"
                }
            }
        },
        {title: '年龄', field: 'customerAge', align: 'center', valign: 'middle', sortable: true, width: 60},
        {title: '缴费金额', field: 'actualAccountBalance', align: 'center', valign: 'middle', sortable: true, width: 80},
        // {title: '赠送余额', field: 'giveAccountBalance', align: 'center', valign: 'middle', sortable: true},
        {
            title: '欠费', field: 'accountarrears', align: 'center', valign: 'middle', sortable: true, width: 80,
            formatter: function (value, row, index) {
                return "<span style='color: red;'>" + row.accountarrears + "</span>"
            }
        },
        // {title: '一级渠道', field: 'oneChannel', align: 'center', valign: 'middle', sortable: true},
        // {title: '二级渠道', field: 'twoChannel', align: 'center', valign: 'middle', sortable: true},
        // {title: '三级渠道', field: 'thrChannel', align: 'center', valign: 'middle', sortable: true},
        {
            title: '客户状态', field: 'xcustomerStatus', align: 'center', valign: 'middle', sortable: true, width: 90,
            formatter: function (value, row, index) {
                return "<a href='javascript:;' onclick='Consultant.choicexCustomerStatus(" + '"' + row.id + '"' + ")'>" + row.xcustomerStatus + "</a>"

            }
        },
        {
            title: '看诊状态', field: 'diagnosisStatus', align: 'center', valign: 'middle', sortable: true, width: 80,
            formatter: function (value, row, index) {
                if (row.diagnosisContent == "" || row.diagnosisContent == null) {
                    row.diagnosisContent = "无看诊详情";
                } else {
                    var reg = /@,/g;
                    row.diagnosisContent = "@," + "看诊详情：" + "@," + row.diagnosisContent
                    row.diagnosisContent = row.diagnosisContent.replace(reg, '&#10;');
                    var regs = /@/g;
                    row.diagnosisContent = row.diagnosisContent.replace(regs, '');
                }
                if (value == "已看诊") {
                    return "<a href='javascript:;' onclick='Consultant.consultantToDetailkz(" + '"' + row.id + '"' + ")'>" +
                        "<span style=' cursor:pointer' title='" + row.diagnosisContent + "'>[已看诊]</span></a>"
                    // return "<a href='javascript:;' onclick='Consultant.opendealStatus(" + '"' + row.reservationsId + '"' + ")'>[已成交]</a>"
                } else {
                    return "<a href='javascript:;' onclick='Consultant.consultantToDetailkz(" + '"' + row.id + '"' + ")'>" +
                        "<span style=' cursor:pointer' title='" + row.diagnosisContent + "'>未看诊</span></a>"
                }
            }
        },
        {
            title: '成交状态', field: 'dealStatus', align: 'center', valign: 'middle', sortable: true, width: 80,
            formatter: function (value, row, index) {
                function leftTrim(str) {
                    return str.replace(/^\s*/g, "");
                }

                if (row.huifang == "" || row.huifang == null) {
                    row.huifang = "无回访详情";
                } else {
                    // row.huifang =",<b>"+"回访详情：" +row.huifang.trim().replace(/\s/g,"");
                    row.huifang = ",<b>" + "回访详情：" + row.huifang.replace(/\s{2,}/g, "");
                    var reg = /,<b>/g;
                    var regs = /<\/b>/g;
                    row.huifang = row.huifang.replace(reg, '&#10;');
                    row.huifang = row.huifang.replace(regs, ' ');
                }
                if (value == "已成交") {
                    return "<a href='javascript:;' onclick='Consultant.consultantToDetailhf(" + '"' + row.id + '"' + ")'>" +
                        "<span style=' cursor:pointer' title='" + row.huifang + "'>[已成交]</span></a>"
                    // return "<a href='javascript:;' onclick='Consultant.opendealStatus(" + '"' + row.reservationsId + '"' + ")'>[已成交]</a>"
                } else {
                    return "<a href='javascript:;' onclick='Consultant.consultantToDetailhf(" + '"' + row.id + '"' + ")'>" +
                        "<span style=' cursor:pointer' title='" + row.huifang + "'>未成交</span></a>"
                }
            }
        },
        {title: 'TC', field: 'fieldTc', align: 'center', valign: 'middle', sortable: true, width: 80},
        {
            title: '跟踪状态', field: 'followStatus', align: 'center', valign: 'middle', sortable: true, width: 100,
        },
        {
            title: '消费状态', field: 'consumptionStatus', align: 'center', valign: 'middle', sortable: true, width: 100,
        },
        {
            title: '回访时间', field: 'appointmentTime', align: 'center', valign: 'middle', sortable: true, width: 95,
            formatter: function (value, row, index) {
                return value.substring(0, 19);
            }
        },
        {
            title: '初诊时间', field: 'firstVisitDate', align: 'center', valign: 'middle', sortable: true, width: 100,
        },
        {
            title: '到店时间', field: 'arrivalTime', align: 'center', valign: 'middle', sortable: true, width: 95,
            formatter: function (value, row, index) {
                return value.substring(0, 19);
            }
        },
        {title: '回访', field: 'huifang', align: 'center', valign: 'middle',width: 100},
        {title: '看诊详情', field: 'diagnosisContent',  align: 'center', valign: 'middle',width: 100},
        {
            title: '客户状态旧', field: 'customerStatus', align: 'center', valign: 'middle',width: 100,
            formatter: function (value, row, index) {
                return "<a href='javascript:;' onclick='Consultant.choiceCustomerStatus(" + '"' + row.id + '"' + ")'>" + row.customerStatus + "</a>"

            }
        }
    ]
    return columns;
};

/**
 * 点击姓名进入详情
 */
Consultant.consultantToDetail = function (id) {
    var index = layer.open({
        type: 2,
        title: '操作',
        area: ['100%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultantTwo/consultantToDetail/' + id
    });
    this.layerIndex = index;
};

/**
 * 点击成交状态进入详情
 */
Consultant.consultantToDetailhf = function (id) {
    var index = layer.open({
        type: 2,
        title: '操作',
        area: ['100%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultantTwo/consultantToDetailhf/' + id
    });
    this.layerIndex = index;
};

/**
 * 点击进入看诊详情
 */
Consultant.consultantToDetailkz = function (id) {
    var index = layer.open({
        type: 2,
        title: '操作',
        area: ['100%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultantTwo/consultantToDetailkz/' + id
    });
    this.layerIndex = index;
};

/**
 * 选择客户状态
 * @param id
 */
Consultant.choiceCustomerStatus = function (id) {
    var index = layer.open({
        type: 2,
        title: '选择客户状态',
        area: ['60%', '60%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/to_choice_status/' + id
    });
    this.layerIndex = index;
};

/**
 * 选择客户状态
 * @param id
 */
Consultant.choicexCustomerStatus = function (id) {
    var index = layer.open({
        type: 2,
        title: '选择客户状态',
        area: ['60%', '60%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/to_choice_statusx/' + id
    });
    this.layerIndex = index;
};

/**
 * 点击预约客户
 */
Consultant.openscDetail = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '预约客户详情',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservations/reservations_details/' + reservationsId
    });
    this.layerIndex = index;
};

Consultant.updateDoctor = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '分配医生',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/consultant/to_updateDoctor/' + Consultant.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 修改跟踪结束
 */
/**Consultant.followEnd = function (id) {
    if (this.check()) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/consultant/update_follow_status/" + Consultant.seItem.id, function (data) {
                Feng.success("修改成功!");
                Consultant.table.refresh();
            }, function (data) {
                Feng.error("修改失败!" + data.responseJSON.message + "!");
            });
            // ajax.set("id", Reservations.seItem.id);
            ajax.start();
        };
        Feng.confirm("确认修改 " + Consultant.seItem.title + "?", operation);
    }
}*/


Consultant.opendealStatus = function (id) {
    $.ajax({
        url: Feng.ctxPath + "/reservations/getTotleMoneys",
        type: "post",
        data: {
            "id": id
        },
        success: function (data) {
            alert("成交金额：" + data + "元");
        },
        error: function (data) {
            alert('内部故障!');
        }
    });
};
Consultant.isOperation = function (id) {
    var index = layer.open({
        type: 2,
        title: '开单操作',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/isOperation/' + id
    });
    this.layerIndex = index;
};

Consultant.isNoOperation = function (id) {
    var index = layer.open({
        type: 2,
        title: '不成交操作',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/isNoOperation/' + id
    });
    this.layerIndex = index;
};

Consultant.openAddVisited = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '添加回访记录',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/to_addVisited/' + reservationsId
    });
    this.layerIndex = index;
};

Consultant.openRevisit = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '预约回访详情',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/openRevisit/' + reservationsId
    });
    this.layerIndex = index;
};

Consultant.openNoRevisit = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '不回访原因',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/openNoRevisit/' + reservationsId
    });
    this.layerIndex = index;
};

Consultant.noDealRecord = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '成交记录',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/deal_detail/' + reservationsId
    });
    this.layerIndex = index;
};

Consultant.openBile = function (ids) {
    var index = layer.open({
        type: 2,
        title: '成交记录',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/to_openBileList/' + ids
    });
    this.layerIndex = index;
};

Consultant.openNoOperation = function (ids) {
    var index = layer.open({
        type: 2,
        title: '未成交记录',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/to_openNoOperation/' + ids
    });
    this.layerIndex = index;
};

Consultant.openRevisitRecord = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '回访记录',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/to_revisitRecord/' + reservationsId
    });
    this.layerIndex = index;
};

Consultant.revisitOperation = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '回访操作',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/to_revisitOperation/' + reservationsId
    });
    this.layerIndex = index;
};

/**
 * 打开查看预约客户详情
 */
Consultant.openqtDetail = function (id) {
    var index = layer.open({
        type: 2,
        title: '预约客户详情',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/customer_details/' + id
    });
    this.layerIndex = index;
};

/**
 * 检查是否选中
 */
Consultant.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        Consultant.seItem = selected[0];
        return true;
    }
};


/**
 *
 */
Consultant.openConsultantDetail = function (id) {
    var index = layer.open({
        type: 2,
        title: 'TC看诊',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/consultant_diagnosis/' + id
    });
    this.layerIndex = index;
};
Consultant.updateDiagnosisDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '看诊详情',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/consultant/consultant_update/' + Consultant.seItem.id
        });
        this.layerIndex = index;
    }
};


/**
 * 打开看诊详情
 */
Consultant.setDiagnosisRecord = function (cr) {
    var index = layer.open({
        type: 2,
        title: '看诊记录',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/diagnosis_details/' + cr
    });
    this.layerIndex = index;
};
/**
 * 删除预约客户
 */
Consultant.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/consultant/delete/" + this.seItem.id, function (data) {
            Feng.success("删除成功!");
            Consultant.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.start();
    }
};


/**
 * 统计总人数
 */
Consultant.total = function () {
    //获取跟踪人数
    var param1 = $("#startArrivalTime").val();  //开始到店时间
    var param2 = $("#endArrivalTime").val();   //结束到店时间
    var param3 = $("#followStatus").val();  // 跟踪状态
    var param4 = $("#consumptionStatus").val(); //消费状态
    var param5 = $("#fieldTcValue").val();
    var param7 = $("#dealStatus").val();   //成交状态
    var param6 = $("#reach").val();
    $.ajax({
        type: "GET",
        url: Feng.ctxPath + "/consultantTwo/total",
        data: {
            param1: param1, param2: param2, param3: param3, param4: param4, param5: param5
            , param6: param6, param7: param7
        },
        dataType: "json",
        success: function (data) {
            $("#total").html(data[0].countNum);//总人数
            $("#first").html(data[1].countNum);//初到
            $("#firstjieya").html(data[2].countNum);//初到洁牙
            $("#firstZhiliao").html(data[3].countNum);//初治
            $("#two").html(data[4].countNum);//复到
            $("#twojieya").html(data[5].countNum);//复到洁牙
            $("#twoZhiliao").html(data[6].countNum);//复到初治
            $("#wash").html(data[7].countNum);//流失
            $("#again").html(data[8].countNum);//再消
        }
    });
};

Consultant.inquire = function () {
    // Consultant.tracking()
    document.getElementById("fieldTcValue").value = $("#fieldTc").val();
    Consultant.search();
}

//总人数数据详情
Consultant.totalNumber = function () {
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    queryData['followStatus'] = $("#followStatus").val();// 跟踪状态
    queryData['dealStatus'] = $("#dealStatus").val();// 成交状态
    queryData['consumptionStatus'] = $("#consumptionStatus").val();//消费状态
    queryData['fieldTc'] = $("#fieldTcValue").val();
    queryData['reach'] = $("#reach").val();
    queryData['customerStatus'] = ""//加入客户状态，总人数
    queryData['xcustomerStatus'] = ""//加入客户状态，总人数
    Consultant.table.refresh({query: queryData});
}
//初到数据详情
Consultant.firstNumber = function () {
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    queryData['followStatus'] = $("#followStatus").val();// 跟踪状态
    queryData['dealStatus'] = $("#dealStatus").val();// 成交状态
    queryData['consumptionStatus'] = $("#consumptionStatus").val();//消费状态
    queryData['fieldTc'] = $("#fieldTcValue").val();
    queryData['reach'] = $("#reach").val();
    // queryData['customerStatus'] = "新客首次"//加入客户状态，新客首次
    queryData['xcustomerStatus'] = "'初到','初治','流失'"//加入客户状态，新客首次
    Consultant.table.refresh({query: queryData});
}
//初到洁牙数据详情
Consultant.firstjieyaNumber = function () {
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    queryData['followStatus'] = $("#followStatus").val();// 跟踪状态
    queryData['dealStatus'] = $("#dealStatus").val();// 成交状态
    queryData['consumptionStatus'] = $("#consumptionStatus").val();//消费状态
    queryData['fieldTc'] = $("#fieldTcValue").val();
    queryData['reach'] = $("#reach").val();
    // queryData['customerStatus'] = "新客二次"//加入客户状态，新客二次
    queryData['xcustomerStatus'] = "'初到洁牙'"//加入客户状态，新客二次
    Consultant.table.refresh({query: queryData});
}
//初治数据详情
Consultant.firstZhiliaoNumber = function () {
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    queryData['followStatus'] = $("#followStatus").val();// 跟踪状态
    queryData['dealStatus'] = $("#dealStatus").val();// 成交状态
    queryData['consumptionStatus'] = $("#consumptionStatus").val();//消费状态
    queryData['fieldTc'] = $("#fieldTcValue").val();
    queryData['reach'] = $("#reach").val();
    // queryData['customerStatus'] = "老客"//加入客户状态，老客
    queryData['xcustomerStatus'] = "'初治'"//加入客户状态，老客
    Consultant.table.refresh({query: queryData});
}
//复到数据详情
Consultant.twoNumber = function () {
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    queryData['followStatus'] = $("#followStatus").val();// 跟踪状态
    queryData['dealStatus'] = $("#dealStatus").val();// 成交状态
    queryData['consumptionStatus'] = $("#consumptionStatus").val();//消费状态
    queryData['fieldTc'] = $("#fieldTcValue").val();
    queryData['reach'] = $("#reach").val();
    // queryData['customerStatus'] = "复诊"//加入客户状态，复诊
    queryData['xcustomerStatus'] = "'复到','复到初治'"//加入客户状态，复诊
    Consultant.table.refresh({query: queryData});
}
//复到洁牙数据详情
Consultant.twojieyaNumber = function () {
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    queryData['followStatus'] = $("#followStatus").val();// 跟踪状态
    queryData['dealStatus'] = $("#dealStatus").val();// 成交状态
    queryData['consumptionStatus'] = $("#consumptionStatus").val();//消费状态
    queryData['fieldTc'] = $("#fieldTcValue").val();
    queryData['reach'] = $("#reach").val();
    // queryData['customerStatus'] = "复诊"//加入客户状态，复诊
    queryData['xcustomerStatus'] = "'复到洁牙'"//加入客户状态，复诊
    Consultant.table.refresh({query: queryData});
}
//复到初治数据详情
Consultant.twoZhiliaoNumber = function () {
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    queryData['followStatus'] = $("#followStatus").val();// 跟踪状态
    queryData['dealStatus'] = $("#dealStatus").val();// 成交状态
    queryData['consumptionStatus'] = $("#consumptionStatus").val();//消费状态
    queryData['fieldTc'] = $("#fieldTcValue").val();
    queryData['reach'] = $("#reach").val();
    // queryData['customerStatus'] = "复诊"//加入客户状态，复诊
    queryData['xcustomerStatus'] = "'复到初治'"//加入客户状态，复诊
    Consultant.table.refresh({query: queryData});
}
//流失数据详情
Consultant.washNumber = function () {
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    queryData['followStatus'] = $("#followStatus").val();// 跟踪状态
    queryData['dealStatus'] = $("#dealStatus").val();// 成交状态
    queryData['consumptionStatus'] = $("#consumptionStatus").val();//消费状态
    queryData['fieldTc'] = $("#fieldTcValue").val();
    queryData['reach'] = $("#reach").val();
    // queryData['customerStatus'] = "复诊"//加入客户状态，复诊
    queryData['xcustomerStatus'] = "'流失'"//加入客户状态，复诊
    Consultant.table.refresh({query: queryData});
}
//再消数据详情
Consultant.againNumber = function () {
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    queryData['followStatus'] = $("#followStatus").val();// 跟踪状态
    queryData['dealStatus'] = $("#dealStatus").val();// 成交状态
    queryData['consumptionStatus'] = $("#consumptionStatus").val();//消费状态
    queryData['fieldTc'] = $("#fieldTcValue").val();
    queryData['reach'] = $("#reach").val();
    // queryData['customerStatus'] = "复诊"//加入客户状态，复诊
    queryData['xcustomerStatus'] = "'再消'"//加入客户状态，复诊
    Consultant.table.refresh({query: queryData});
}
/**
 * 查询预约客户列表
 */
Consultant.search = function () {
    Consultant.table.refresh({query: Consultant.formParams()});
    Consultant.total();
};

Consultant.searchRevisit = function () {
    Consultant.table.refresh({query: Consultant.formParamss()});
};
var myDate = new Date();
var month;
var day;
if ((myDate.getMonth() + 1) < 10) {
    month = "0" + (myDate.getMonth() + 1);
} else {
    month = "" + (myDate.getMonth() + 1);
}
if (myDate.getDate() < 10) {
    day = "0" + myDate.getDate();
} else {
    day = "" + myDate.getDate();
}
Consultant.formParamss = function () {
    var queryData = {};
    queryData['reach'] = $("#reach").val();
    queryData['customerName'] = $("#customerName").val();
    queryData['customerPhone'] = $("#customerPhone").val();
    queryData['startArrivalTime'] = $("#startArrivalTime").val();
    queryData['endArrivalTime'] = $("#endArrivalTime").val();
    queryData['reservations'] = $("#reservations").val();
    queryData['startRevisitTime'] = $("#startRevisitTime").val();
    queryData['endRevisitTime'] = $("#endRevisitTime").val();
    queryData['isReturnVisit'] = $("#isReturnVisit").val();
    queryData['doctor'] = $("#doctor").val();
    // queryData['customerStatus'] = $("#customerStatus").val();
    queryData['xcustomerStatus'] = $("#xcustomerStatus").val();
    queryData['followStatus'] = $("#followStatus").val();
    queryData['consumptionStatus'] = $("#consumptionStatus").val();
    queryData['fieldTc'] = $("#fieldTcValue").val();
    queryData['dealStatus'] = $("#dealStatus").val();
    queryData['backVisit'] = "1";
    document.getElementById("backVisit").value = "1";
    // queryData['oneChannel'] = $("#oneChannel").val();
    // queryData['twoChannel'] = $("#twoChannel").val();
    // queryData['thrChannel'] = $("#thrChannel").val();
    return queryData;
}

//把对象拼接成URL的键值对参数param1=value1&param2=value2
var parseParam = function (param) {
    var paramStr = "";

    $.each(param, function (i) {
        paramStr += '&' + getSingleData(param, i);
    });
    return paramStr.substr(1);
};

var getSingleData = function (param, key) {
    return key + "=" + param[key];
}

Consultant.downLoad = function () {
    var queryData = {};
    queryData['reach'] = $("#reach").val();
    queryData['startArrivalTime'] = $("#startArrivalTime").val();
    queryData['endArrivalTime'] = $("#endArrivalTime").val();
    queryData['followStatus'] = $("#followStatus").val();
    queryData['dealStatus'] = $("#dealStatus").val();
    queryData['consumptionStatus'] = $("#consumptionStatus").val();
    queryData['fieldTc'] = $("#fieldTcValue").val();
    queryData['backVisit'] = $("#backVisit").val();
    var param = parseParam(queryData);
    location.href = Feng.ctxPath + '/consultant/consultantExport?' + param;
}


Consultant.resetSearch = function () {
    $("#followStatus").val("");
    $("#dealStatus").val("");
    $("#consumptionStatus").val("");
    $("#reach").val("");
    $("#fieldTcValue").val("");
    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    Consultant.search();
};

Consultant.todaySupplement = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#isReturnVisit").val("");
    $("#doctor").val("");
    $("#customerStatus").val("");
    $("#xcustomerStatus").val("");
    $("#fieldTcValue").val("");
    $("#dealStatus").val("");
    document.getElementById("startRevisitTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endRevisitTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    Consultant.search();
};

Consultant.tomorrowSupplement = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#isReturnVisit").val("");
    $("#doctor").val("");
    $("#customerStatus").val("");
    $("#xcustomerStatus").val("");
    $("#fieldTcValue").val("");
    $("#dealStatus").val("");
    var myDates = new Date();
    myDates.setDate(myDates.getDate() + 1);
    var months;
    var days;
    if ((myDates.getMonth() + 1) < 10) {
        months = "0" + (myDates.getMonth() + 1);
    } else {
        months = "" + (myDates.getMonth() + 1);
    }
    if (myDates.getDate() < 10) {
        days = "0" + myDates.getDate();
    } else {
        days = "" + myDates.getDate();
    }
    document.getElementById("startRevisitTime").value = myDates.getFullYear() + "-" + months + "-" + days + " " + "00:00:00";
    document.getElementById("endRevisitTime").value = myDates.getFullYear() + "-" + months + "-" + days + " " + "23:59:59";
    Consultant.search();
};

/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
Consultant.formParams = function () {
    var queryData = {};
    queryData['reach'] = $("#reach").val();
    queryData['startArrivalTime'] = $("#startArrivalTime").val();
    queryData['endArrivalTime'] = $("#endArrivalTime").val();
    queryData['fieldTc'] = $('#fieldTcValue').val();
    queryData['followStatus'] = $("#followStatus").val();
    queryData['dealStatus'] = $("#dealStatus").val();
    queryData['consumptionStatus'] = $("#consumptionStatus").val();

    queryData['backVisit'] = "";
    // queryData['dealStatus'] = $("#dealStatus").val();
    // queryData['oneChannel'] = $("#oneChannel").val();
    // queryData['twoChannel'] = $("#twoChannel").val();
    // queryData['thrChannel'] = $("#thrChannel").val();
    //alert(JSON.stringify(queryData));
    return queryData;
}

$(function () {
    var fieldTcValueinto=document.getElementById("fieldTcValue").value;
    var ii=0;
    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    var defaultColunms = Consultant.initColumn();
    var table = new BSTable(Consultant.id, "/consultant/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(Consultant.formParams);
    Consultant.table = table.init();

    var menuName = $("#menuName").val();
    $.ajax({
        url: Feng.ctxPath + "/reservation/reservation_initialization",
        type: "post",
        data: {
            "menuName": menuName
        },
        success: function (data) {
            if(data != ""){
                var item = data.listx1.split("，");
                for(var i = 0 ; i < item.length ; i++){
                    $('#ConsultantTable').bootstrapTable('hideColumn', item[i]);
                }
            }
        }
    });

    //初始化下拉经济能力列表
    $.post(Feng.ctxPath + "/tc/getList", function (data) {
        var txt = '<option value="">--请选择现场TC--</option>';
        for (var i = 0; i < data.length; i++) {
            txt += '<option value="' + data[i].tcName + '">' + data[i].tcName + '</option>';
            if(data[i].tcName==fieldTcValueinto){
                ii++;
            }
        }
        document.getElementById('fieldTc').innerHTML = txt;
        //状态单选
        var seletefieldTc = $('#fieldTcValue').val();
        if (seletefieldTc != "") {
            $("#fieldTc option[value=" + seletefieldTc + "]").attr("selected", "selected");
        }
        if(ii==0){
            document.getElementById('fieldTcValue').value="";
        }
        Consultant.search();
    }, "json");
    // Consultant.total();

    //采用定时器监听 时间内容是否变化
    var startArrivalTimeTwo = $("#startArrivalTime").val();
    var endArrivalTimeTwo = $("#endArrivalTime").val();

    setInterval(
        function () {//定时执行方法内容
            if ($("#startArrivalTime").val() != startArrivalTimeTwo || $("#endArrivalTime").val() != endArrivalTimeTwo) {//如果时间发生变化，就触发查询事件
                Consultant.search()
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                startArrivalTimeTwo = $("#startArrivalTime").val();
                endArrivalTimeTwo = $("#endArrivalTime").val();
            }
        }, 500);
});
